package com.tanhua.server.service;

/**
 * @Author: cl
 * @Date: 2022/5/7 - 05 - 07
 * @Description:
 */

import com.tanhua.dubbo.api.UserApi;
import com.tanhua.model.domain.User;
import com.tanhua.model.vo.ErrorResult;
import com.tanhua.model.vo.HuanXinUserVo;
import com.tanhua.server.exception.BusinessException;
import com.tanhua.server.interceptor.UserHolder;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * 环信即时通讯模块
 */
@Service
public class HuanXinService {

    @DubboReference
    private UserApi userApi;

    /**
     * 用户登录后获取环信账户密码(两种方式，1通过用户名查询数据库，2直接拼接返回)
     *
     * @return
     */
    public HuanXinUserVo getHuanXinUser() {
        //1、通过用户id查询数据库
        User user = userApi.findById(UserHolder.getUserId());
        //2、封装vo返回
        if (user == null) {
            throw new BusinessException(ErrorResult.error());
        }
        HuanXinUserVo huanXinUserVo = new HuanXinUserVo();
        huanXinUserVo.setUsername(user.getHxUser());
        huanXinUserVo.setPassword(user.getHxPassword());
        return huanXinUserVo;
    }
}
